#ifndef _YAML_HANDLER_H
#define _YAML_HANDLER_H

#include <yaml-cpp/yaml.h>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <unistd.h>

//yaml文件中每个map的行数的最大值
#define LINESPERMAP 11

std::string peekString(std::string src, int index);

class YamlHandler
{
    bool dump();
    bool copyTemp(std::string srcFilename, std::string dstFilename);
    bool deleteOneLine(int row);
    YAML::Node node;
    std::string path;
    int lines_per_map;
public:
    YamlHandler(int lpm){
        this->lines_per_map = lpm;
    }
    YamlHandler(std::string _path){
        this->path = _path;
        this->node = YAML::LoadFile(this->path);
    }
    ~YamlHandler(){
        //this->dump();
    }
    bool loadFile(std::string _path);
    //最大支持二级查找
    std::string read(std::string lable1, std::string lable2 = "");
    std::string readList(int num, std::string lable);
    bool writeList(int num, std::string lable, std::string content);
    bool deleteOneMap(int index);
    int lines();
    std::string currentPath();
    int linesPerMap();
    int numofMap();
};

#endif
